package day0106

import . "gocode/algorithm/utils"

func mergeTwoLists1(list1 *ListNode, list2 *ListNode) *ListNode {
	head := &ListNode{}
	tmp := head
	for list1 != nil && list2 != nil {
		if list1.Val > list2.Val {
			tmp.Next = list2
			list2 = list2.Next
		} else {
			tmp.Next = list1
			list1 = list1.Next
		}
		tmp = tmp.Next
	}
	if list1 == nil {
		tmp.Next = list2
	} else if list2 == nil {
		tmp.Next = list1
	}
	return head.Next
}
func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
	if nil == list1 {
		return list2
	}
	if nil == list2 {
		return list1
	}
	if list1.Val > list2.Val {
		list2.Next = mergeTwoLists1(list2.Next, list1)
		return list2
	} else {
		list1.Next = mergeTwoLists1(list1.Next, list2)
		return list1
	}
}
